package com.itjiange.service.judge.config;

import org.springframework.amqp.core.*;
import com.rabbitmq.client.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ItJianGe
 * @data 2024/4/15 11:17
 */
@Configuration
public class RabbitConfig {

    @Value("${myRabbitmq.host}")
    private String host;

    @Bean // 创建连接工厂
    public ConnectionFactory connectionFactory() {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(host);
        return factory;
    }

    @Bean // 创建交换机
    public DirectExchange exchange() {
        return new DirectExchange("code_exchange");
    }

    @Bean // 创建队列
    public Queue queue() {
        return new Queue("code_queue", true, false, false);
    }

    @Bean // 绑定队列到交换机
    public Binding binding() {
        return BindingBuilder.bind(queue()).to(exchange()).with("my_routingKey");
    }
}
